load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "insights",
    srcs = [
        "causes.go",
        "detector.go",
        "ingester.go",
        "insights.go",
        "pool.go",
        "provider.go",
        "registry.go",
        "store.go",
        "test_utils.go",
    ],
    embed = [":insights_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/insights",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql/appstatspb",
        "//pkg/sql/clusterunique",
        "//pkg/sql/contention/contentionutils",
        "//pkg/util/cache",
        "//pkg/util/intsets",
        "//pkg/util/metric",
        "//pkg/util/quantile",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_prometheus_client_model//go",
    ],
)

go_test(
    name = "insights_test",
    srcs = [
        "causes_test.go",
        "detector_test.go",
        "ingester_test.go",
        "insights_test.go",
        "registry_test.go",
        "store_test.go",
    ],
    data = glob(["testdata/**"]),
    embed = [":insights"],
    deps = [
        "//pkg/settings/cluster",
        "//pkg/sql/appstatspb",
        "//pkg/sql/clusterunique",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/stop",
        "//pkg/util/uint128",
        "//pkg/util/uuid",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "insights_proto",
    srcs = ["insights.proto"],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

go_proto_library(
    name = "insights_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/insights",
    proto = ":insights_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/util/uuid",  # keep
        "@com_github_gogo_protobuf//gogoproto",
    ],
)
